﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <el-form ref="formRefMaterialDoc" :model="stateMaterialDoc.vmModel" label-width="100px">
    <div style="margin-bottom:10px;">{{$t('message.autotrans.SysBatchEditConfirm')}}</div>
    <el-row>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Name_FormItem" prop="LinkedVM.Name" :label="$t('message.autotrans._Model_MaterialDoc_Name')">
          <el-input v-model="stateMaterialDoc.vmModel.LinkedVM.Name" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Spec_FormItem" prop="LinkedVM.Spec" :label="$t('message.autotrans._Model_MaterialDoc_Spec')"          :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_MaterialDoc_Spec')}), trigger: 'blur' }]" >
          <el-input v-model="stateMaterialDoc.vmModel.LinkedVM.Spec" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Unit_FormItem" prop="LinkedVM.Unit" :label="$t('message.autotrans._Model_MaterialDoc_Unit')">
          <el-input v-model="stateMaterialDoc.vmModel.LinkedVM.Unit" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_ErpCode_FormItem" prop="LinkedVM.ErpCode" :label="$t('message.autotrans._Model_MaterialDoc_ErpCode')">
          <el-input v-model="stateMaterialDoc.vmModel.LinkedVM.ErpCode" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_MaterialProperty_FormItem" prop="LinkedVM.MaterialProperty" :label="$t('message.autotrans._Model_MaterialDoc_MaterialProperty')"          :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_MaterialDoc_MaterialProperty')}), trigger: 'blur' }]" >
          <el-select v-model="stateMaterialDoc.vmModel.LinkedVM.MaterialProperty" clearable>
             <el-option key="Master" value="Master" :label="$t('message.autotrans._Enum_MaterialPropertyEnum_Master')"></el-option>
             <el-option key="Batch" value="Batch" :label="$t('message.autotrans._Enum_MaterialPropertyEnum_Batch')"></el-option>
             <el-option key="None" value="None" :label="$t('message.autotrans._Enum_MaterialPropertyEnum_None')"></el-option>
          </el-select>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_MaterialType_FormItem" prop="LinkedVM.MaterialType" :label="$t('message.autotrans._Model_MaterialDoc_MaterialType')"          :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_MaterialDoc_MaterialType')}), trigger: 'blur' }]" >
          <el-select v-model="stateMaterialDoc.vmModel.LinkedVM.MaterialType" clearable>
             <el-option key="FERT" value="FERT" :label="$t('message.autotrans._Enum_MaterialClassifyEnum_FERT')"></el-option>
             <el-option key="HALB" value="HALB" :label="$t('message.autotrans._Enum_MaterialClassifyEnum_HALB')"></el-option>
             <el-option key="ROH" value="ROH" :label="$t('message.autotrans._Enum_MaterialClassifyEnum_ROH')"></el-option>
          </el-select>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Expiration_FormItem" prop="LinkedVM.Expiration" :label="$t('message.autotrans._Model_MaterialDoc_Expiration')">
          <el-input v-model="stateMaterialDoc.vmModel.LinkedVM.Expiration" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Rules_FormItem" prop="LinkedVM.Rules" :label="$t('message.autotrans._Model_MaterialDoc_Rules')"          :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_MaterialDoc_Rules')}), trigger: 'blur' }]" >
          <el-input type="textarea" v-model="stateMaterialDoc.vmModel.LinkedVM.Rules" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Supplier_FormItem" prop="LinkedVM.Supplier" :label="$t('message.autotrans._Model_MaterialDoc_Supplier')">
          <el-input v-model="stateMaterialDoc.vmModel.LinkedVM.Supplier" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Pos_FormItem" prop="LinkedVM.Pos" :label="$t('message.autotrans._Model_MaterialDoc_Pos')">
          <el-input v-model="stateMaterialDoc.vmModel.LinkedVM.Pos" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Active_FormItem" prop="LinkedVM.Active" :label="$t('message.autotrans._Model_MaterialDoc_Active')"          :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_MaterialDoc_Active')}), trigger: 'blur' }]" >
          <el-switch v-model="stateMaterialDoc.vmModel.LinkedVM.Active" clearable></el-switch>
      </el-form-item>

      </el-col>
    </el-row>

    <div style="text-align:right;">
      <WtmButton @click="onSubmitMaterialDoc"  type="primary" :button-text="$t('message.autotrans.SysSubmit')" style="margin-top:15px;"/>

      <WtmButton @click="onCloseMaterialDoc"  type="primary" :button-text="$t('message.autotrans.SysClose')" style="margin-top:15px;"/>

    </div>

  </el-form>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageWmsManagementMaterialDocBatchEdit;false">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { materialdocApi } from '/@/api/wmsmanagement/materialdoc';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;


// 定义变量内容
const formRefMaterialDoc = ref();
const stateMaterialDoc = reactive({
    vmModel: {
	  LinkedVM:{
        Name: '',
        Spec: '',
        Unit: '',
        ErpCode: '',
        MaterialProperty: undefined,
        MaterialType: undefined,
        Rules: '',
        Supplier: '',
        Pos: '',
        Active: undefined,
      },
      Ids:[],
      
	},
    
});

// 取消
const onCloseMaterialDoc = () => {
    closeDialog();
};

// 提交
const onSubmitMaterialDoc = () => {
	const loadingInstance = ElLoading.service({
		lock: true,
		text: '正在提交中，请等待。。。',
		background: 'rgba(0, 0, 0, 0.7)',
	});

    formRefMaterialDoc.value?.validate((valid: boolean, fields: any) => {
		if (valid) {
            materialdocApi().batchedit(stateMaterialDoc.vmModel).then(() => {
                ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
                emit('refresh');
                closeDialog();
            }).catch((error:any) => {
                other.setFormError(ci, error);
            }).finally(() => {
			loadingInstance.close();
		    })
		}
        else{
			loadingInstance.close();
        }
	})
};


// 页面加载时
onMounted(() => {
    
    if (ci.attrs["wtmdata"]) {
		stateMaterialDoc.vmModel.Ids = ci.attrs["wtmdata"];
	}
	else if (useRouter().currentRoute.value.query.id) {
		stateMaterialDoc.vmModel.Ids = useRouter().currentRoute.value.query.id as any;
	}

});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh','closeDialog']);
// 关闭弹窗
const closeDialog = () => {
    emit('closeDialog');
};
// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

